﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion


#region Usings

using System;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Surface.Presentation;
using ScrumTable.BL.DM.DataManagement;
using ScrumTable.UI.View.Controls;
using ScrumTable.UI.View.Extension;
using ScrumTable.UI.ViewModel;

#endregion

namespace ScrumTable.UI.View.WinTouch.UserControls.Menu
{
 

    /// <summary>
    /// Interaction logic for ContextMenu.xaml
    /// </summary>
    public partial class DropSpecificControl : IDropUserControl
    {
        private Func<object, bool> _canDrop;
        private object _value;
        private Action<object> _actionDrop;

        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

 
        
        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        public Array States { get; set; }
        public Type ViewModelType { get; private set; }
        
        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

         
        public DropSpecificControl()
        {
            DataContext = this;
            InitializeComponent();
        }


        public DropSpecificControl(Func<object, bool> canDrop, object value, Action<object> actionDrop)
        {
            _actionDrop = actionDrop;
            _value = value;
            _canDrop = canDrop;
            AllowDrop = true;
            DataContext = this;
            SurfaceDragDrop.AddDropHandler(this, OnDropHandler);
            InitializeComponent();
            ControlText.Content = value.ToString();
        }


        private void OnDropHandler(object sender, SurfaceDragDropEventArgs args)
        {
            if (CanDrop(args.Cursor.Data)==CanDropResult.CanDrop)
            {
                _actionDrop(_value);
            }
        }

 
        #endregion

        public FrameworkElement GetRootControl
        {
            get { return DropRoot; }
        }

        public bool ShowIconWithbackground
        {
            get { return false; }
        }

        public CanDropResult CanDrop(object objectToDrop)
        {
            return this.ConvertBoolToEnum(_canDrop(objectToDrop));
        }


    }

    /*
    #region DropStateControl<T>
    public class DropSpecificControl<T> : UserControl, IDropUserControl
    {
        private Func<object, T, bool> _canDrop;
        private T _state;
        private IScrumItemViewModel<DomainBase> _viewModel;

        public DropSpecificControl(Func<object, T, bool> canDrop, T value, IScrumItemViewModel<DomainBase> viewModel)
        {
            _state = value;
            _canDrop = canDrop;
            SurfaceDragDrop.AddDropHandler(this, OnDropHandler);
            Content = new DropStateControl(value);
            AllowDrop = true;
            _viewModel = viewModel;
        }

        private void OnDropHandler(object sender, SurfaceDragDropEventArgs args)
        {
            if (CanDrop(args.Cursor.Data))
            {
                _viewModel.EnumState = (Enum) (object) _state;
            }
        }


        #region

        public FrameworkElement GetRootControl
        {
            get { return ((DropStateControl)Content).DropRoot; }
        }

        public bool ShowIconWithbackground
        {
            get { return false; }
        }

        public bool CanDrop(object objectToDrop)
        {
            return _canDrop(objectToDrop, _state);
        }
        #endregion

       
    }
    #endregion*/
}
